package ui
{
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.utils.Dictionary;
	
	import mx.managers.PopUpManager;
	import mx.managers.SystemManager;

	/**
	 *窗口管理类 
	 * @author SXT
	 */
	public class UiManager
	{
		private static var _instance:UiManager;
		/**
		 *对象池 
		 */		
		private var winDic:Dictionary;
		private var _uiSprite:DisplayObject;
		
		public function UiManager(key:Key)
		{
			winDic = new Dictionary();
			_uiSprite = SystemManager.getSWFRoot(Game.instance.main);
		}
		
		public static function get instance():UiManager{
			if(_instance == null){
				_instance = new UiManager(new Key);
			}
			return _instance;
		}
		/**
		 *显示一个窗口 
		 * @param win
		 */		
		public function addWin(win:Class,center:Boolean=true):void{
			if(winDic[win]){
				PopUpManager.addPopUp(winDic[win],uiSprite);
			}else{
				winDic[win] = PopUpManager.createPopUp(uiSprite,win);
				if(center){
					PopUpManager.centerPopUp(winDic[win]);
				}
			}
		}
		/**
		 *移出窗口 
		 * @param win
		 */		
		public function removeWin(win:Class):void{
			if(winDic[win]){
				PopUpManager.removePopUp(winDic[win]);
			}
		}

		/**
		 *ui层 
		 */
		public function get uiSprite():DisplayObject
		{
			return _uiSprite;
		}

	}
}
class Key{}